﻿Public Class ClsAction
    'represents action

#Region "Attributes"
#Region "Private attributes"
    Private MeAction As GeAction = GeAction.kkNoAction 'action of action object
    Private MoData As Collection = New Collection 'data for action
    Private MoOriginalCursor As Cursor 'original cursor before action is running
#End Region
#End Region
#Region "Constructors"
    Sub New(ByVal IeAction As GeAction)
        MeAction = IeAction
        'remember original cursor
        MoOriginalCursor = Cursor.Current
        Cursor.Current = Cursors.AppStarting
    End Sub
#End Region
#Region "Destructors"
    Protected Overrides Sub Finalize()
        MyBase.Finalize()
        MeAction = GeAction.kkNoAction
        MoData.Clear()
        'set back original cursor
        Cursor.Current = MoOriginalCursor
    End Sub
#End Region
#Region "Properties"
#Region "Public attributes"
    Public Property Action() As GeAction
        Get
            Return MeAction
        End Get
        Set(ByVal IeValue As GeAction)
            MeAction = IeValue
        End Set
    End Property
#End Region
#End Region
#Region "Subs"
    'sets data for action
    Public Function SetData(ByRef OoObject As Object, ByVal IsKey As String) As GeActionResult
        Try
            If IsInCollection(MoData, IsKey) Then
                RemoveData(IsKey)
            End If
            MoData.Add(OoObject, IsKey)
            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
#End Region
#Region "Functions"
    'gets data of action
    Public Function GetData(ByVal IsKey As String) As Object
        Try
            Return MoData(IsKey)
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return Nothing
        End Try
    End Function
    'gets data of action, return default value if key doesnt exist
    Public Function GetData(ByVal IsKey As String, ByVal IoDefaultValue As Object) As Object
        Try
            Return MoData(IsKey)
        Catch ex As Exception
            LogEventFromException(ex, , , False)
            Return IoDefaultValue
        End Try
    End Function
    'removes data from action
    Public Function RemoveData(ByVal IsKey As String) As GeActionResult
        Try
            MoData.Remove(IsKey)
            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'is key in collection?
    Private Function IsInCollectionOfAction(ByVal IsKey As String) As Boolean
        Return IsInCollection(MoData, IsKey)
    End Function
#End Region
End Class
